﻿<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:sys="clr-namespace:System;assembly=mscorlib" 
  xmlns:controls="clr-namespace:iTuner.Controls"
  xmlns:resx="clr-namespace:iTuner.Properties"
  mc:Ignorable="d" d:DesignHeight="58" d:DesignWidth="250"
  x:Class="iTuner.TaskPanel"
  x:ClassModifier="internal"
  Background="Transparent">

  <UserControl.Resources>

    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <!-- Main Button Styles -->

    <Style x:Key="ShuffleButtonStyle" TargetType="{x:Type ToggleButton}">
      <Setter Property="SnapsToDevicePixels" Value="True"/>
      <Setter Property="OverridesDefaultStyle" Value="True"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type ToggleButton}">
            <Border Name="FnBorder" CornerRadius="2" BorderThickness="1" BorderBrush="Transparent">
              <Grid>
                <Image x:Name="Son" Source="Images\Tasks\ShuffleOn.png" Width="16" Height="16" Visibility="Hidden" />
                <Image x:Name="Soff" Source="Images\Tasks\Shuffle.png" Width="16" Height="16" Visibility="Visible" />
              </Grid>
            </Border>
            <ControlTemplate.Triggers>
              <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="FnBorder" Property="BorderBrush" Value="{StaticResource fnButtonStroke}" />
                <Setter TargetName="FnBorder" Property="Background" Value="{StaticResource fnButtonFill}" />
              </Trigger>
              <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="FnBorder" Property="Background" Value="{StaticResource fnButtonPressed}" />
              </Trigger>
              <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="Son" Property="Visibility" Value="Visible" />
                <Setter TargetName="Soff" Property="Visibility" Value="Hidden" />
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <Style x:Key="LyricsButtonStyle" TargetType="{x:Type Button}">
      <Setter Property="SnapsToDevicePixels" Value="True"/>
      <Setter Property="OverridesDefaultStyle" Value="True"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type Button}">
            <Border Name="FnBorder" CornerRadius="2" BorderThickness="1" BorderBrush="Transparent">
              <Image x:Name="img" Source="Images\Lyrics\LyricsOn.png" Width="16" Height="16" />
            </Border>
            <ControlTemplate.Triggers>
              <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="FnBorder" Property="BorderBrush" Value="{StaticResource fnButtonStroke}" />
                <Setter TargetName="FnBorder" Property="Background" Value="{StaticResource fnButtonFill}" />
              </Trigger>
              <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="FnBorder" Property="Background" Value="{StaticResource fnButtonPressed}" />
              </Trigger>
              <Trigger Property="Tag" Value="">
                <Setter TargetName="img" Property="Source" Value="Images\Lyrics\LyricsOn.png" />
                <Setter Property="IsEnabled" Value="True" />
              </Trigger>
              <Trigger Property="Tag" Value="0">
                <Setter TargetName="img" Property="Source" Value="Images\Lyrics\LyricsOff.png" />
                <Setter Property="IsEnabled" Value="False" />
              </Trigger>
              <Trigger Property="Tag" Value="1">
                <Setter TargetName="img" Property="Source" Value="Images\Lyrics\LyricsOff1.png" />
                <Setter Property="IsEnabled" Value="False" />
              </Trigger>
              <Trigger Property="Tag" Value="2">
                <Setter TargetName="img" Property="Source" Value="Images\Lyrics\LyricsOff2.png" />
                <Setter Property="IsEnabled" Value="False" />
              </Trigger>
              <Trigger Property="Tag" Value="3">
                <Setter TargetName="img" Property="Source" Value="Images\Lyrics\LyricsOff3.png" />
                <Setter Property="IsEnabled" Value="False" />
              </Trigger>
              <Trigger Property="Tag" Value="4">
                <Setter TargetName="img" Property="Source" Value="Images\Lyrics\LyricsOff4.png" />
                <Setter Property="IsEnabled" Value="False" />
              </Trigger>
              <Trigger Property="Tag" Value="5">
                <Setter TargetName="img" Property="Source" Value="Images\Lyrics\LyricsOff5.png" />
                <Setter Property="IsEnabled" Value="False" />
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <!-- ListBoxItem TaskItemStyle -->

    <Style x:Key="TaskItemStyle" TargetType="{x:Type ListBoxItem}">
      <Setter Property="Focusable" Value="False" />
      <Setter Property="Foreground" Value="Black" />
      <Setter Property="HorizontalContentAlignment" Value="Stretch" />
      <Setter Property="Margin" Value="0" />
      <Setter Property="Padding" Value="0,0,0,1" />
      <Setter Property="FontSize" Value="12"/>
      <Setter Property="FontFamily" Value="Calibri"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type ListBoxItem}">
            <Border
              x:Name="Bd" SnapsToDevicePixels="true"
              Background="Transparent" BorderThickness="0" Padding="0">
              <ContentPresenter
                x:Name="PART_Header"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </Border>
            <ControlTemplate.Triggers>
              <Trigger Property="IsSelected" Value="true">
                <Setter Property="Background" TargetName="Bd" Value="Transparent"/>
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <!-- Scrollbar Styles -->

    <SolidColorBrush x:Key="NormalBrush" Color="#00585858"/>
    <SolidColorBrush x:Key="GlyphBrush" Color="#FF7E7C7C" />
    <SolidColorBrush x:Key="ThumbBrush" Color="#407E7C7C" />
    <SolidColorBrush x:Key="GlyphMouseOver" Color="#FFE8E8E8"/>
    <SolidColorBrush x:Key="PressedBrush" Color="Black"/>
    <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />

    <Style x:Key="ScrollBarLineButton" TargetType="{x:Type RepeatButton}">
      <Setter Property="SnapsToDevicePixels" Value="True"/>
      <Setter Property="OverridesDefaultStyle" Value="true"/>
      <Setter Property="Focusable" Value="false"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type RepeatButton}">
            <Border 
              Name="Border"
              Margin="1" 
              CornerRadius="3" 
              Background="{StaticResource NormalBrush}"
              BorderBrush="{StaticResource NormalBrush}"
              BorderThickness="1">
              <Path
                Name="glyph"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Fill="{StaticResource GlyphBrush}"
                Data="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" />
            </Border>
            <ControlTemplate.Triggers>
              <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="glyph" Property="Fill" Value="{StaticResource GlyphMouseOver}"/>
              </Trigger>
              <Trigger Property="IsPressed" Value="true">
                <Setter TargetName="glyph" Property="Fill" Value="{StaticResource PressedBrush}" />
              </Trigger>
              <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
      <Setter Property="SnapsToDevicePixels" Value="True"/>
      <Setter Property="OverridesDefaultStyle" Value="true"/>
      <Setter Property="IsTabStop" Value="false"/>
      <Setter Property="Focusable" Value="false"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type RepeatButton}">
            <Border Background="Transparent" />
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
      <Setter Property="SnapsToDevicePixels" Value="True"/>
      <Setter Property="OverridesDefaultStyle" Value="true"/>
      <Setter Property="IsTabStop" Value="false"/>
      <Setter Property="Focusable" Value="false"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type Thumb}">
            <Rectangle
              Name="rectThumb"
              RadiusX="4"
              RadiusY="4" 
              Fill="{StaticResource ThumbBrush}"/>
            <ControlTemplate.Triggers>
              <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="rectThumb" Property="Fill" Value="{StaticResource GlyphMouseOver}"/>
              </Trigger>
              <Trigger Property="IsDragging" Value="true">
                <Setter TargetName="rectThumb" Property="Fill" Value="Black"/>
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
      <Grid >
        <Grid.RowDefinitions>
          <RowDefinition MaxHeight="18"/>
          <RowDefinition Height="0.0001*"/>
          <RowDefinition MaxHeight="18"/>
        </Grid.RowDefinitions>
        <Border
          Grid.RowSpan="3"
          CornerRadius="3"
          BorderBrush="#45202020" BorderThickness=".5"
          Background="{StaticResource NormalBrush}" />
        <RepeatButton 
          Grid.Row="0" 
          Style="{StaticResource ScrollBarLineButton}"
          Height="18"
          Command="ScrollBar.LineUpCommand"
          Content="M 0 8 L 8 8 L 4 0 Z" />
        <Track 
          Name="PART_Track"
          Grid.Row="1"
          IsDirectionReversed="true">
          <Track.DecreaseRepeatButton>
            <RepeatButton 
              Style="{StaticResource ScrollBarPageButton}"
              Command="ScrollBar.PageUpCommand" />
          </Track.DecreaseRepeatButton>
          <Track.Thumb>
            <Thumb 
              Style="{StaticResource ScrollBarThumb}" 
              Margin="3,0,3,0"
              Background="{StaticResource GlyphBrush}" />
          </Track.Thumb>
          <Track.IncreaseRepeatButton>
            <RepeatButton 
              Style="{StaticResource ScrollBarPageButton}"
              Command="ScrollBar.PageDownCommand" />
          </Track.IncreaseRepeatButton>
        </Track>
        <RepeatButton 
          Grid.Row="3" 
          Style="{StaticResource ScrollBarLineButton}"
          Height="18"
          Command="ScrollBar.LineDownCommand"
          Content="M 0 0 L 4 8 L 8 0 Z"/>
      </Grid>
    </ControlTemplate>

    <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
      <Setter Property="SnapsToDevicePixels" Value="True"/>
      <Setter Property="OverridesDefaultStyle" Value="true"/>
      <Style.Triggers>
        <Trigger Property="Orientation" Value="Vertical">
          <Setter Property="Width" Value="13"/>
          <Setter Property="Height" Value="Auto" />
          <Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
        </Trigger>
      </Style.Triggers>
    </Style>

  </UserControl.Resources>

  <Border x:Name="Container">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="{Binding ElementName=Container,Path=ActualWidth}" />
      </Grid.ColumnDefinitions>

      <Grid x:Name="actionPane" Visibility="Visible" Margin="3,0,3,0">
        <Grid.RowDefinitions>
          <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <ToggleButton
          x:Name="EditKeyButton" Focusable="False"
          Width="80" Style="{StaticResource FnToggleButtonStyle}"
          Click="DoEditKeys">
          <StackPanel
            Orientation="Vertical" HorizontalAlignment="Center" Margin="4"
            Grid.Column="0" Grid.RowSpan="2">
            <Image Source="Images\Tasks\Keyboard64t.png" Width="64" Height="34" />
            <TextBlock
              Text="{x:Static resx:Resources.TaskPanel_SetHotKeys}" HorizontalAlignment="Center"
              FontFamily="Segoe UI Semibold" FontSize="10.667"/>
          </StackPanel>
        </ToggleButton>

        <StackPanel Orientation="Vertical" Grid.Column="1" VerticalAlignment="Center">
          <ToggleButton
            x:Name="ShuffleButton" Focusable="False"
            Width="22" Height="22" ToolTip="{x:Static resx:Resources.TaskPanel_ToggleShuffle}"
            Style="{StaticResource ShuffleButtonStyle}"
            IsChecked="{Binding Shuffle}" />
          <Button
            x:Name="LyricsButton" Focusable="False"
            Width="22" Height="22" Margin="0,4,0,0"
            ToolTip="{x:Static resx:Resources.TaskPanel_ShowLyrics}" ToolTipService.ShowOnDisabled="True"
            Style="{StaticResource LyricsButtonStyle}"
            Click="DoShowLyrics" />
        </StackPanel>

        <Button
          Grid.Column="2" Width="80" Style="{StaticResource FnButtonStyle}"
          Click="DoShowiTunes" Focusable="False">
          <StackPanel
            Orientation="Vertical" HorizontalAlignment="Center" Margin="4"
            Grid.Column="1" Grid.RowSpan="2">
            <Image x:Name="iTunesLogo" Source="Images\Tasks\iTunesLogo.png" Width="64" Height="34" />
            <TextBlock
              Text="{x:Static resx:Resources.TaskPanel_ShowiTunes}" HorizontalAlignment="Center"
              FontFamily="Segoe UI Semibold" FontSize="10.667"/>
          </StackPanel>
        </Button>
      </Grid>

      <Grid x:Name="taskPane" Margin="4,0,17,0" Visibility="Hidden">
        <ListBox
          x:Name="taskList"
          SelectionMode="Single"
                ItemContainerStyle="{StaticResource TaskItemStyle}"
          Grid.IsSharedSizeScope="True"
          Background="Transparent" BorderThickness="0"
          ScrollViewer.CanContentScroll="False">
          <ListBox.ItemTemplate>
            <DataTemplate>
              <Grid HorizontalAlignment="Stretch" DockPanel.Dock="Top">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition SharedSizeGroup="TaskNameGroup"/>
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock
                  Text="{Binding Description}" Grid.Column="0" Padding="3,0,3,0"
                  ToolTip="{Binding Tooltip}"/>
                <ProgressBar
                  Height="8" Width="Auto" Grid.Column="1" Margin="0,0,3,0"
                  Value="{Binding ProgressPercentage, Mode=OneWay}"
                  ToolTip="{Binding ProgressPercentage, Mode=OneWay}" />
              </Grid>
            </DataTemplate>
          </ListBox.ItemTemplate>
        </ListBox>
        <StackPanel
          x:Name="emptyBlock" Orientation="Vertical" Visibility="Visible"
          VerticalAlignment="Center" HorizontalAlignment="Center">
          <TextBlock Text="{x:Static resx:Resources.TaskPanel_NoTasks}" FontStyle="Italic" />
          <TextBlock x:Name="optionsLink" Margin="0,4,0,0" Style="{StaticResource LinkBlockStyle}">
            <Hyperlink Click="DoChangeOptions" MouseEnter="DoEnterLink" MouseLeave="DoLeaveLink">
              <Run Text="{x:Static resx:Resources.TaskPanel_ChangeOptions}"/>
            </Hyperlink>
          </TextBlock>
        </StackPanel>
      </Grid>

      <ToggleButton
        x:Name="flipper" ToolTip="{x:Static resx:Resources.TaskPanel_ChangeView}" Focusable="False"
        Style="{StaticResource FlipButtonStyle}" Width="11" Height="11"
        HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,4,4,0"
        Click="DoToggleView"  />

    </Grid>
  </Border>

</UserControl>
